package com.stu.dcxy.design.creatation.prototype;

import java.util.HashMap;
import java.util.Map;

/**
 * @Classname Mybatis
 * @Version 1.0.0
 * @Date 2022/3/30 16:33
 * @Created by yd
 */
public class Mybatis {
    private Map<String, User> userCache = new HashMap<String, User>();

    public User getUser(String username) {
        if (userCache.containsKey(username)) {
            return userCache.get(username);
        }
        User user = getUserFromDb(username);
        userCache.put(username, user);
        return user;
    }

    public User getUserFromDb(String username) {
        System.out.println("Mybatis.getUserFromDb" + username);
        User user = new User();
        user.setUsername(username);
        user.setAge(1);
        return user;
    }
}
